package org.idea.qiyu.framework.threadpool.async.controller;

import org.idea.qiyu.framework.threadpool.async.service.ArticleServiceImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author linhao
 * @Date created in 10:13 下午 2021/10/24
 */
@RestController
public class ArticleController {

    @Resource
    private ArticleServiceImpl articleService;

    @GetMapping(value = "/do-test-0")
    public void doTest0(){
        articleService.doTest();
        articleService.updateCount();
    }

    @GetMapping(value = "/do-test")
    public void doTest(){
        System.out.println("this is do test");
        this.updateCount();
        System.out.println("更新任务线程"+Thread.currentThread().getName());
        System.out.println("this is end");
    }

    //怀疑是不是在controller内部不会生效
    @Async
    public void updateCount() {
        System.out.println("========");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("++++++++");
        System.out.println("更新任务线程"+Thread.currentThread().getName());
    }


}
